#ifndef GAMESCREEN_H
#define GAMESCREEN_H


#include "SFML\Graphics\RenderWindow.hpp"
#include "SFML\Audio.hpp"
#include "SFML\Graphics\Text.hpp"
#include <rapidjson\rapidjson.h>
#include <rapidjson\document.h>
#include <rapidjson\reader.h>
#include <rapidjson\filestream.h>
#include <rapidjson\prettywriter.h>
#include "Box2D\Box2D.h"
#include "Screens\ScreenBase.h"
#include "Camera.h"

using namespace sf;
using namespace rapidjson;
using namespace std;

class Player;



class GameScreen : public ScreenBase, public b2ContactListener{
public:
	GameScreen(GameState *gameState);

	~GameScreen();

	void init();

	void update(double ms);

	void draw();

	void drawUI();

	void restoreCheckPoint();

	void saveCheckPoint();

	void loadState(const string &filename);

	void loadStateDeferred(const string &filename);

	void saveState(const string &filename);

	void saveStateDeferred(const string &filename);

	void clean();

	void writeObject(PrettyWriter<FileStream> &writer, GameObject *object);

	GameObject* createObject(const Value &object);

	void addDefaultObjects();

	void addObject(GameObject* object, int layer = -1);

	virtual void BeginContact(b2Contact* contact);

    virtual void EndContact(b2Contact* contact);

    virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);

    virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);

	void addDot() { m_dots++; }

	Music& getMusic() { return m_music; }

	

private:
	// Physics
	b2World m_world;

	// Time handling
	double m_currentTime;

	double m_accumulator;

	// Player
	Player *m_player;

	// State
	string m_nextLoadState;

	string m_nextSaveState;

	bool m_hasCheckpoint;

	int m_dots;

	float m_totalDots;

	Music m_music;

	

	
};
#endif